﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace System.Drawing
{
    public class RectangleUtils
    {
        /// <summary>
        /// Liefert das Rechteck vom übergebenen Bereich,
        /// abzüglich der inneren Abstände zurück, in der gezeichnet werden kann.
        /// </summary>
        /// <param name="clipRectangle"></param>
        /// <param name="padding"></param>
        /// <returns></returns>
        public static Rectangle RectanglePaint(Rectangle clipRectangle, Padding padding)
        {
            if (padding.All > -1)
            {
                return new Rectangle(clipRectangle.X + padding.All,
                                     clipRectangle.Y + padding.All,
                                     clipRectangle.Width - padding.Horizontal,
                                     clipRectangle.Height - padding.Vertical);
            }
            else
            {
                return new Rectangle(clipRectangle.X + padding.Left,
                                     clipRectangle.Y + padding.Top,
                                     clipRectangle.Width - padding.Horizontal,
                                     clipRectangle.Height - padding.Vertical);
            }
        }

        public static RectangleF ConvertToRectangleF(Rectangle rectangle)
        {
            RectangleF rect = new RectangleF(Convert.ToSingle(rectangle.X),
                                             Convert.ToSingle(rectangle.Y),
                                             Convert.ToSingle(rectangle.Width),
                                             Convert.ToSingle(rectangle.Height));

            return rect;
        }

        public static void Inflate(ref Rectangle rect, int width, int height)
        {
            rect.Width += width;
            rect.Height += height;
        }

        public static void Inflate(ref Rectangle rect, Size size)
        {
            Inflate(ref rect, size.Width, size.Height);
        }

        public static void Inflate(ref RectangleF rect, float width, float height)
        {
            rect.Width += width;
            rect.Height += height;
        }

        public static void Inflate(ref RectangleF rect, Size size)
        {
            Inflate(ref rect, size.Width, size.Height);
        }

        public static void OffSet(ref Rectangle rectSrc, int x, int y)
        {
            rectSrc.X += x;
            rectSrc.Y += y;
            rectSrc.Width += x;
            rectSrc.Height += y;
        }

        public static void OffSet(ref RectangleF rectSrc, float x, float y)
        {
            rectSrc.X += x;
            rectSrc.Y += y;
            rectSrc.Width += x;
            rectSrc.Height += y;
        }
    }
}
